<?php
require_once('inc/init.php');
require_once('inc/pager.php');
require_once getCacheFilePath('forums.php');
require_once('header.php');
$headtitle="在线用户";

$online_row=$db->row_query("Select k,Count(0) As ct From(Select case when userid=0 then 'eq0' else 'neq0' end as k From `{$db->pre}online`)A Group By k");
$online_guessnum=0;
$online_usernum=0;
foreach($online_row as $tmp){
	if($tmp['k']=='eq0'){
		$online_guessnum=intval($tmp['ct']);
	}elseif($tmp['k']=='neq0'){
		$online_usernum=intval($tmp['ct']);
	}
}

$online_allnum=$online_usernum+$online_guessnum;

	$curPage = numFilter($_GET["page"]);
	$pager = new Pager();
	$pager->init($cache_settings['userspernum'], $curPage, "online.php?page={page}");
	$rows = $pager->queryRowsBySQL($db,"Select * From (Select (case When userid=0 then 0 else 1 end) As user_mark,{$db->pre}online.* From {$db->pre}online) {$db->pre}online Order By user_mark desc,activetime desc",$online_allnum);
	

$cache1=$db->row_select_one("cache1");
if($online_allnum>$cache1['mostonlinenum']){
	$cache1_new['mostonlinenum']=$cache1['mostonlinenum']=$online_allnum;
	$cache1_new['mostonlinetime']=$cache1['mostonlinetime']=$_SYS['time'];
	$db->row_update("cache1", $cache1_new);
}
$cache1['mostonlinetime']=getDateStr($cache1['mostonlinetime']);
	foreach($rows as $key=>$row){
		$row['activetime']=getDateStr($row['activetime']);
		$forum=$cache_forums[$row['fid']];
		$row['name']=$row['userid']==0?"游客":"<a href='".genUrl("user.php?uid={$row['userid']}")."' target='_blank'>{$row['username']}</a>";
		$row['ip']=$lg['groupid']<GROUP_FORUMADMIN?"--":"<a href='".str_replace('{ip}',$row['ip'], $cache_settings['iplink'])."' target='_blank'>{$row['ip']}</a>";
		$row['position']='';
		$row['doaction']='';
		switch($row['atpage']){
			case 'forum':
				$row['position']=$cache_forums[$row['fid']]['forumname'];
				$row['doaction']='浏览版块';
			break;

			case 'view':
				$row['position']=$cache_forums[$row['fid']]['forumname'];
				$row['doaction']='浏览帖子';
				$row['title']="<a href='".genUrl("view.php?tid={$row['tid']}")."' target='_blank'>#".$row['tid']."</a>";
			break;

			case 'online':
				$row['doaction']='查看在线用户列表';
			break;

			case 'member':
				$row['doaction']='个人中心';
			break;

			case 'login':
				$row['doaction']='会员登录';
			break;
		
			case 'search':
				$row['doaction']='帖子搜索';
			break;
		
			case 'userlist':
				$row['doaction']='查看会员列表';
			break;

			case 'index':
				$row['doaction']='浏览首页';
			break;

			case 'signup':
				$row['doaction']='注册';
			break;
		
			case 'post':
				$row['doaction']='发布帖子';
			break;
			
			case 'announce':
				$row['doaction']='查看公告';
			break;
		
		}

		$row['onlineicon']=0;
		if($row['groupid']>200){
			$row['onlineicon']=$row['groupid'];
		}elseif($row['groupid']>100){
			$row['onlineicon']=0;
		}else{
			$row['onlineicon']=1;
		}
		$rows[$key]=$row;
	}

require_once getTemplatePath('online.htm');
footer();
?>